import java.util.Date;

import models.*;

import org.junit.Test;

import play.test.Fixtures;
import play.test.UnitTest;

public class Zein extends UnitTest {
	
	@Test
	public void Tagging(){
		IdeaDeveloper ideadeveloper = new IdeaDeveloper("Bakkar Seedon", "Bakkar",
				"Rashida", "bakkar.horus@gmail.com", "1/1/2000", "Owner");
		ideadeveloper.save();
		Idea idea = new Idea("title", "description", ideadeveloper.id);
		idea.save();
		Idea idea2 = new Idea("title2", "description2", ideadeveloper.id);
		idea2.save();
		idea.addTag("aswan");
		idea.save();
		assertEquals(true, idea.existingTag("aswan"));
		idea2.addTag("aswan");
		idea2.save();
		assertEquals(2, ((Tag)Tag.find("name = ?", "aswan").fetch().get(0)).relatedItems);
		idea2.removeTag("aswan");
		idea2.save();
		assertEquals(1, ((Tag)Tag.find("name = ?", "aswan").fetch().get(0)).relatedItems);
		
		Topic topic = new Topic("title", "description", ideadeveloper.id);
		topic.save();
		Topic topic2 = new Topic("title2", "description2", ideadeveloper.id);
		topic2.save();
		topic.addTag("aswan");
		topic.save();
		assertEquals(true, topic.existingTag("aswan"));
		topic2.addTag("aswan");
		topic2.save();
		assertEquals(3, ((Tag)Tag.find("name = ?", "aswan").fetch().get(0)).relatedItems);
		topic2.removeTag("aswan");
		topic2.save();
		assertEquals(2, ((Tag)Tag.find("name = ?", "aswan").fetch().get(0)).relatedItems);
		topic.addTag("Nubia");
		topic.save();
		assertEquals(2, ((Topic)Topic.find("id = ?", topic.id).fetch().get(0)).tags.size());
		idea.addTag("Nubia");
		idea.save();
		assertEquals(2, ((Idea)Idea.find("id = ?", idea.id).fetch().get(0)).tags.size());
	}
	
	@Test
	public void Commenting(){
		IdeaDeveloper ideadeveloper = new IdeaDeveloper("Bakkar Seedon", "Bakkar",
				"Rashida", "bakkar.horus@gmail.com", "1/1/2000", "Owner");
		ideadeveloper.save();
		ActionPlan actionPlan = new ActionPlan();
		actionPlan.name = "Bakkar";
		actionPlan.description = "Description";
		actionPlan.requirment = "req";
		actionPlan.status = "status";
		Date start = new Date(111, 4, 5);
		Date end = new Date(111, 8, 9);
		actionPlan.startDate = start;
		actionPlan.endDate = end;
		actionPlan.save();
		Comment comment = Comment.create(ideadeveloper, actionPlan, "Bakkar's comment");
		Comment comment2 = Comment.create(ideadeveloper, actionPlan, "Rashida's comment");
		assertEquals(2, ((ActionPlan)ActionPlan.find("id = ?", actionPlan.id).fetch().get(0)).comments.size());
		comment2.delete2();
		assertEquals(1, ((ActionPlan)ActionPlan.find("id = ?", actionPlan.id).fetch().get(0)).comments.size());
		Idea idea = new Idea("title", "description", ideadeveloper.id);
		idea.save();
		Comment comment3 = Comment.create(ideadeveloper, idea, "Seedon's comment");
		Comment comment4 = Comment.create(ideadeveloper, idea, "Mashrat's comment");
		assertEquals(2, ((Idea)Idea.find("id = ?", idea.id).fetch().get(0)).comments.size());
		comment4.delete2();
		assertEquals(1, ((Idea)Idea.find("id = ?", idea.id).fetch().get(0)).comments.size());
	}
}
